<?php
/**
 * Created by PhpStorm.
 * User: ysk
 * Date: 2020/5/11
 * Time: 8:42
 */

namespace api\modules\v1\controllers;
use yii\web\Controller;
use Yii;
use common\utils\Http;

class WxController extends Controller{

//    public $enableCsrfValidation = false;

    public $url = 'https://api.weixin.qq.com/sns/jscode2session';
    public $appid = 'wxe847f97083f3dc37';
    public $secret = 'ab0d49a26a87ef849d5a677096e085f8';

    public function beforeAction($action)
    {
        $currentaction = $action->id;

        $nocsrfactions = ['uploadf'];

        if(in_array($currentaction,$nocsrfactions)){
            $action->controller->enableCsrfValidation = false;
        }

        return parent::beforeAction($action); // TODO: Change the autogenerated stub
    }


    /**
     * code2Session
     */
    public function  actionAuth(){

       $arr = [
           'appid'=>$this->appid,
           'secret'=>$this->secret,
           'js_code'=>$_REQUEST['js_code'],
           'grant_type'=>'authorization_code'

       ];

       $res = Http::curlData($this->url,$arr,'GET');
       return $res;

    }

    public function  actionUploadf(){

        $file = isset($_FILES['file'])?$_FILES['file']:[];
        return json_encode($file);

    }



}
